// 登录业务
const username = document.querySelector('#input-email')
const password = document.querySelector('#input-password')
document.querySelector('#btn-login').addEventListener('click', async e => {
    if (username.value.trim().length < 8 || username.value.trim().length > 30) {
        alertMsg('用户名请输入8-30个字符', false)
        return
    }
    if (password.value.trim().length < 6 || password.value.trim().length > 30) {
        alertMsg('密码请输入6-30个字符', false)
        return
    }
    try {
        const res = await axios({
            url: '/login',
            method: 'POST',
            data: {
                username: username.value,
                password: password.value
            }
        })
        localStorage.setItem('hmjytoken', res.data.data.token)
        alertMsg(res.data.message)
        localStorage.setItem('hmjyuname', username.value)
        setTimeout(() => {
            location.href = './index.html'
        }, 1700)
    } catch (error) {
        alertMsg(error.response.data.message, false)
    }
})

document.querySelector('.bi-eye-fill').addEventListener('click', function () {
    if (password.type == 'text') {
        password.type = 'password'
    } else {
        password.type = 'text'
    }
})